import axios from "axios"
import { Message } from "element-ui"
import router from "@/router"
const app = axios.create({
    // baseURL: 'http://admintest.happymmall.com/api',
    
    timeout: 10000

})
app.interceptors.request.use((config) => {
    return config
    
}, error => {
    return Promise.reject(error)
})
app.interceptors.response.use(res => {
    const { msg:msg,status: code, data: result } = res.data
    let changeCode = [200,0]
    if (changeCode.includes(code)) {
        Message({
            message: msg,
            type: 'success'
        })
        return result
    }
    Message({
        message: msg,
        type: 'error'
    })
    if (msg =='用户未登录,请登录'||msg=='出错啦') {
        router.replace('/')
        return
    }
    return Promise.resolve(msg)
    
}, error => {
    return Promise.reject(error)
})
// console.log(app);
export default app